package com.studio701.carguard.controller;



import com.studio701.carguard.pojo.HelpAnswer;
import com.studio701.carguard.pojo.RespBean;

import com.studio701.carguard.service.IHelpAnswerService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/help-answer")
public class HelpAnswerController {

    @Autowired
    IHelpAnswerService iHelpAnswerService;

    @ApiOperation("添加互助回答信息")
    @PostMapping("/")
    public boolean insertHelpAnswer(@RequestBody HelpAnswer helpAnswer){
        return iHelpAnswerService.save(helpAnswer);
    }

    @ApiOperation("修改互助回答信息")
    @PutMapping("/")
    RespBean updateHelpAnswer(@RequestBody HelpAnswer helpAnswer){
        if (iHelpAnswerService.updateHelpAnswerById(helpAnswer)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("删除互助回答信息")
    @DeleteMapping("/")
    RespBean deleteHelpPlan(Integer userId,Integer qId){
        if (iHelpAnswerService.removeHelpAnswerByUserIdAndQID(userId,qId)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

    @ApiOperation("获取某一互助回答信息")
    @GetMapping("/")
    HelpAnswer getByUserIdAndQId(Integer userId, Integer qId){
        return iHelpAnswerService.getByUserIdAndQId(userId, qId);
    }

    @ApiOperation("获取全部互助回答")
    @GetMapping("/{qId}")
    List<HelpAnswer> getByQId(@PathVariable("qId")Integer qId){
        return iHelpAnswerService.getByQId(qId);
    }

}
